import axios from 'axios'
import qs from 'qs'

export default {
  async get (url: string, data: Object) {
    try {
      let res = (await axios.get(url, { params: data }) as any).data
      return new Promise((resolve, reject) => {
        res.code === 0 ? resolve(res) : reject(res)
      })
    } catch (err) {
      alert('服务器出错')
      console.log(err)
    }
  },
  async post (url: string, data: Object) {
    try {
      let res = (await axios.post(url, qs.stringify(data)) as any).data
      return new Promise((resolve, reject) => {
        res.code === 0 ? resolve(res) : reject(res)
      })
    } catch (err) {
      alert('服务器出错')
      console.log(err)
    }
  }
}
